package com.richardjaap.data;

import java.util.ArrayList;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Account {
	
	private int id;
	private String username;
	private String password;
	private double cashTotal;
	private boolean loggedOn = false;
	
	private Player player;
	
	public Account(String username, String password){
		this.id = assignId();
		this.username = username;
		this.password = password;
		setCashTotal(2000.0);
		
	}
	
	public void joinTable(int tableId, double cash){
		player = new Player(this);
		player.joinTable(tableId, cash);
	}
	
	public void leaveTable(){
		cashTotal += player.getCashBuyIn();
		player = null;
	}
	
	public Player getPlayer(){
		return player;
	}
	
	private int assignId(){
		ArrayList<Account> a = Lobby.getInstance().getAccounts();
		return a.size()+1;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isLoggedOn() {
		return loggedOn;
	}

	public void setLoggedOn(boolean loggedOn) {
		this.loggedOn = loggedOn;
	}

	public double getCashTotal() {
		return cashTotal;
	}

	public void setCashTotal(double cashTotal) {
		this.cashTotal = cashTotal;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

}
